declare let eManager;
import DrawOne from "./DrawOne";
const { ccclass, property } = cc._decorator;
//7-2 口红
@ccclass
export default class KouHong extends cc.Component {
    @property
    stepName = "";
    //入场动画
    @property(cc.Animation)
    startAni: cc.Animation = null;
    //涂抹区域 
    @property(cc.Node)
    DrawArea: cc.Node = null;

    @property(DrawOne)
    Draw: DrawOne = null;

    //开盖音效
    @property({type:cc.AudioClip})
    sound_1: cc.AudioClip = null;
    //涂抹音效
    @property({type:cc.AudioClip})
    sound_2: cc.AudioClip = null;


    _isPlay = false;
    _isDone = false;
    _curPoint = 1;//一共2步  先是右眼 再是左眼
    _audioId = 0;
    start() {
        this.startAni.on("finished", this.startFinish, this);
    };
    initData() {
        // eManager.emit("HZ_SHOW_SELECT_LIST", {
        //     step: 7,
        //     point: 2,
        //     // callback:()=>{
        //     //     this.startAni.node.active = true;
        //     //     this.startAni.play();
        //     //     this.scheduleOnce(()=>{
        //     //         cc.audioEngine.play(this.sound_1, false, 1);
        //     //     },0.2);
        //     // }
        // });
        this.startAni.node.active = true;
        this.startAni.play();
        this.scheduleOnce(() => {
            cc.audioEngine.play(this.sound_1, false, 1);
        }, 0.2);
        this._isPlay = true;
        this._audioId = 0;
        eManager.emit("REFRESH_STEP_NAME", this.stepName);
        eManager.emit("HZ_REFRESH_ICON_TIPS", "step_7_2");
    };

    _touchStart(event) {
        if (this._isPlay)
            return;
        if (this._isDone)
            return;
        if (this._audioId > 0) {
            cc.audioEngine.stop(this._audioId);
        }
        this._audioId =  cc.audioEngine.play(this.sound_2, true, 1);
        this.Draw._touchStart(event,cc.v2(-100,130));
    };
    _touchMove(event) {
        if (this._isPlay)
            return;
        if (this._isDone)
            return;
        this.Draw._touchMove(event);
    };

    _touchEnd(event: any) {
        cc.audioEngine.stop(this._audioId);
        this._audioId = 0;
        if (this._isPlay)
            return;
        if (this._isDone)
            return;
        this.Draw._touchEnd(() => {
            this.startAni.node.active = false;
            this._isPlay = true;
            this._isDone = true;
            eManager.emit("DONE_STEP", 7);
            eManager.emit("MINI_DONE_STEP");
            eManager.emit("HZ_MAKE_DOT", {
                makeup_close:7,
                makeup_step:this.stepName
            });
        });
    };

    startFinish() {
        this._isPlay = false;
    };

}
